/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testChatSystem;

import ChatNI.ListenUDP;
import ChatNI.TCPcom;
import ChatNI.UDPcom;
import MVC.ChatController;
import MVC.ConnectionWindow;
import MVC.ModelMessIn;
import MVC.ModelMessOut;
import MVC.ModelUser;
import common.Message;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.LinkedList;

/**
 *
 * @author Duy Duc,Metangmo
 */
public class ChatSystemGR4_RTA2 {

    /**
     * 
     * @param args
     * @throws SocketException
     * @throws UnknownHostException
     */
    public static void main(String[] args) throws SocketException, UnknownHostException {
        
        // Queue of traitement 
        LinkedList<Message> fileMessage = new LinkedList<Message>();
        
        //port UDP=6666
        int desport= 6666; 
        int portecoute= 6666;
        
        //port TCP=5555
        int port = 5555;
        
        // creation of the Controller
        ChatController controller = new ChatController();
        
        // Creation of the models
        ModelUser mod = new ModelUser();
        ModelMessIn model2 = new ModelMessIn();
        ModelMessOut model3 = new ModelMessOut();
        

        //Creation of the threads which listen to this UDP port
        ListenUDP udp2 = null;
        System.out.println ( "Listenning...");
        
        
        UDPcom udp = new UDPcom (portecoute,InetAddress.getLocalHost(),desport,udp2 ,controller,fileMessage);        
        TCPcom tcp = new TCPcom (port,controller );
        
        //MVC definition
        controller.addModel(mod);
        controller.addModelMessIn(model2);
        controller.addModelMessOut(model3);
        
        controller.getModeleMessOut().addObserver(udp);
        controller.getModeleMessOut().addObserver(tcp);
               
        controller.setUdp(udp);
        controller.setTcp(tcp);
        
        ConnectionWindow connectWindow = new ConnectionWindow(controller);
        
        
    }
}
